﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using SPPivotViewer.HttpHandler.Internal;
using System.Net;

namespace SPPivotViewer.HttpHandler
{
    public class SPDziHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
                DziRequest request = new DziRequest(context.Request.Url);
            Collection collection = CollectionCache.Instance.Get(request.CollectionKey);
            if (null == collection)
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                context.Response.StatusDescription = "Pivot image data not found. Cache may have expired.";
                return;
            }

            CollectionItem item = collection.Items[request.ItemId];
            ImageProviderBase image = item.ImageProvider;

            context.Response.ContentType = "text/xml";
            DziSerializer.Serialize(context.Response.Output, image.Size);
        }
    }
}
